package com.atwulidun.flyweight10;

import java.util.Collection;
// 注意：这里图书馆所维护的图书列表就是内部状态；借阅书籍的学生就是外部状态
public class FlyWeightDemo {
    public static void main(String[] args) {
        // 获取图书馆单例对象
        Library library = Library.getInstance();

        // 借阅三本书籍
        System.out.println("图书馆书籍借阅记录：");
        Book book1 = library.borrow("java编程思想");
        book1.borrow(new Student("张三"));
        Book book2 = library.borrow("java核心卷一");
        book2.borrow(new Student("李四"));
        Book book3 = library.borrow("java从入门到精通");
        book3.borrow(new Student("王五"));
        Book book4 = library.borrow("java编程思想");
        book4.borrow(new Student("赵六"));
        Book book5 = library.borrow("java核心卷一");
        book5.borrow(new Student("钱七"));

        // 打印出图书馆所维护的图书列表里的书籍
        System.out.println("图书馆列表里的书籍：");
        Collection<Book> values = library.getBooksPool().values();
        for (Book value : values) {
            System.out.println(value.getName());
        }
    }
}
